<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<link rel="stylesheet" href="${webcontext}/res/style/S.css" />
	<script type="text/javascript" src="${webcontext}/res/js/jquery.min.js"></script>
	<script type="text/javascript" src="${webcontext}/res/js/S.js"></script>
	<script type="text/javascript">
		$(function(){
			
			var tbl = new S.Table({
				el:'#tbl001',
				pager:true,
				pageSize:30,
				dbclick:function(data){
					editSetting(data);
				},
				menus:{
					'修改':function(tr){
						var idx = $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						editSetting(data);
					},
					'删除':function(tr){
						var idx = $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						deleteSetting([data]);
					}
				},
				renders:{
					'value':function(value){
						return S.summary(value,100);
					}
				}
			});
			
			$('#btn_setting_add').click(function(){
				var dlg = new S.Dialog({
					title:'增加',
					width:400,
					height:300,
					modal:true,
					url:'${webcontext}/${pathvar.admin}/blog/setting/edit',
					buttons:{
						'保存':function(){
							if(!this.form.validate()){new S.Info({text:'信息填写不完整',type:'warn'}).show();return;}
							S.request({
								url:'${webcontext}/${pathvar.admin}/blog/setting/save',
								data:this.form.param(),
								success:function(){
									new S.Info({text:'操作成功',type:'sluccess'}).show();
									tbl.reload();
									dlg.remove();
								}
							});
						},
						'关闭':function(){
							this.remove();
						}
					}
				});
				dlg.show();
			});
			
			function editSetting(data){

				var dlg = new S.Dialog({
					title:'编辑',
					width:400,
					height:300,
					modal:true,
					url:'${webcontext}/${pathvar.admin}/blog/setting/edit?id='+data.id,
					buttons:{
						'修改':function(){
							if(!this.form.validate()){new S.Info({text:'信息填写不完整',type:'warn'}).show();return;}
							S.request({
								url:'${webcontext}/${pathvar.admin}/blog/setting/update',
								data:this.form.param(),
								success:function(){
									new S.Info({text:'操作成功',type:'sluccess'}).show();
									tbl.reload();
									dlg.remove();
								}
							});
						},
						'关闭':function(){
							this.remove();
						}
					}
				});
				dlg.show();
			}
			
			
			$('#btn_setting_edit').click(function(){
				
				var items = tbl.getCheckedRow();
				if(items.length !=1){new S.Info({text:'请选择1条信息',type:'warn'}).show();return;}
				
				editSetting(items[0]);
			});
			
			
			function deleteSetting(items){
				S.confirm('警告','确认要删除选中项?',function(){
					var ids = [];
					S.each(items,function(i,item){
						ids.push(item.id);
					});
					S.request({
						url:'${webcontext}/${pathvar.admin}/blog/setting/delete',
						data:{ids:ids.join(',')},
						success:function(){
							
						}
					});
				},'danger');
			}
			
			$('#btn_setting_delete').click(function(){
				
				var items = tbl.getCheckedRow();
				if(items.length == 0){new S.Info({text:'请选择设置项',type:'warn'}).show();return;}
				
				deleteSetting(items);
			});
		});
	</script>
</head>
<body>
	<div class="filled-box">
		<div class="toolbar">
			<span class="btn" id="btn_setting_add"><i class="icons plus"></i> 增加</span>
			<span class="btn" id="btn_setting_edit"><i class="icons pencil"></i> 修改</span>
			<span class="btn" id="btn_setting_delete"><i class="icons cross"></i> 删除</span>
		</div>
		<div class="content">
			<table id="tbl001" height="500" ds="${webcontext }/${pathvar.admin}/blog/setting/list">
				<tr>
					<td width="30" seq></td>
					<td width="50" checkall></td>
					<td width="100">name</td>
					<td width="100">code</td>
					<td >value</td>
				</tr>
				<tr>
					<td>@{seq}</td>
					<td><input type="checkbox" name="id" value="@{id}" /></td>
					<td>@{name}</td>
					<td>@{code}</td>
					<td>@{value}</td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>
	